home *** CD-ROM | disk | FTP | other *** search
- package com.opera;
-
- import java.io.File;
- import java.io.FilePermission;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.SocketPermission;
- import java.net.URL;
- import java.net.URLClassLoader;
- import java.net.URLConnection;
- import java.security.AccessController;
- import java.security.AllPermission;
- import java.security.CodeSource;
- import java.security.PermissionCollection;
- import java.util.Enumeration;
- import java.util.PropertyPermission;
-
- public class PluginClassLoader extends URLClassLoader {
- private static RuntimePermission usePolicyPermission = new RuntimePermission("usePolicy");
- private static PropertyPermission browserReadPerm = new PropertyPermission("browser", "read");
- private static PropertyPermission browserVerReadPerm = new PropertyPermission("browser.version", "read");
- private URL codeBase;
- String key;
- private AppContextAdapter appContext = null;
- private ThreadGroup threadGroup = null;
- private int usageCount = 0;
- private Object usageCountSync = new Object();
-
- URL getCodeBase() {
- return this.codeBase;
- }
-
- String getKey() {
- return this.key;
- }
-
- public PluginClassLoader(URL var1, String var2) {
- super(new URL[0]);
- this.codeBase = var1;
- this.key = var2;
- }
-
- public void addJar(URL var1) {
- this.addURL(var1);
- }
-
- ThreadGroup getThreadGroup() {
- try {
- if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
- this.threadGroup = new ThreadGroup(this.codeBase + "-threadGroup");
- this.threadGroup.setMaxPriority(4);
- AppContextCreator var1 = new AppContextCreator(this.threadGroup);
- var1.setContextClassLoader(this);
- synchronized(var1.syncObject) {
- var1.start();
-
- try {
- var1.syncObject.wait();
- } catch (InterruptedException var5) {
- }
-
- this.appContext = var1.appContext;
- }
-
- Object var8 = null;
- }
- } catch (Exception var7) {
- var7.printStackTrace(System.err);
- }
-
- return this.threadGroup;
- }
-
- protected int getUsageCount() {
- return this.usageCount;
- }
-
- protected void grab() {
- synchronized(this.usageCountSync) {
- ++this.usageCount;
- this.getThreadGroup();
- }
- }
-
- protected void release() {
- synchronized(this.usageCountSync) {
- if (this.usageCount > 1) {
- --this.usageCount;
- } else {
- if (this.appContext != null) {
- try {
- this.appContext.dispose();
- } catch (IllegalThreadStateException var4) {
- var4.printStackTrace(System.err);
- }
- }
-
- this.usageCount = 0;
- this.appContext = null;
- this.threadGroup = null;
- PluginPanel.cacheClassLoader(this);
- }
-
- }
- }
-
- public AppContextAdapter getAppContext() {
- return this.appContext;
- }
-
- public PermissionCollection getPermissions(CodeSource var1) {
- PermissionCollection var2 = super.getPermissions(var1);
- URL var3 = var1.getLocation();
- if (var3.getProtocol().equals("file")) {
- String var4 = var3.getFile().replace('/', File.separatorChar);
- if (!var4.endsWith(File.separator)) {
- int var5 = var4.lastIndexOf(File.separatorChar);
- if (var5 != -1) {
- var4 = var4.substring(0, var5 + 1) + "-";
- var2.add(new FilePermission(var4, "read"));
- }
- }
-
- var2.add(new SocketPermission("localhost", "connect,accept"));
- AccessController.doPrivileged(new 1(this, var2));
- if (this.codeBase.getProtocol().equals("file")) {
- String var7 = this.codeBase.getFile().replace('/', File.separatorChar);
- if (var7.endsWith(File.separator)) {
- var7 = var7 + "-";
- }
-
- var2.add(new FilePermission(var7, "read"));
- }
- }
-
- var2.add(browserReadPerm);
- var2.add(browserVerReadPerm);
- if (var1.getCertificates() != null && !var2.implies(usePolicyPermission) && this.allPermissionsGranted(var1)) {
- var2.add(new AllPermission());
- }
-
- return var2;
- }
-
- boolean allPermissionsGranted(CodeSource var1) {
- return System.getProperty("browser.opera.useCertificateHandler").equals("true") ? CertificateHandler.checkCertificates(var1) : false;
- }
-
- public URL findResource(String var1) {
- URL var2 = super.findResource(var1);
- if (var2 == null) {
- try {
- var2 = new URL(this.codeBase, var1);
- if (!this.resourceExists(var2)) {
- var2 = null;
- }
- } catch (Exception var4) {
- var2 = null;
- }
- }
-
- return var2;
- }
-
- private boolean resourceExists(URL var1) {
- boolean var2 = true;
-
- try {
- URLConnection var3 = var1.openConnection();
- if (var3 instanceof HttpURLConnection) {
- HttpURLConnection var4 = (HttpURLConnection)var3;
- int var5 = var4.getResponseCode();
- if (var5 == 200) {
- return true;
- }
-
- if (var5 >= 400) {
- return false;
- }
- } else {
- InputStream var7 = var3.getInputStream();
- var7.close();
- }
- } catch (Exception var6) {
- var2 = false;
- }
-
- return var2;
- }
-
- public Enumeration findResources(String var1) throws IOException {
- if (var1 != null && var1.indexOf("META-INF/services/javax.sound") != -1) {
- return new 2(this);
- } else {
- URL var2 = new URL(this.codeBase, var1);
- if (!this.resourceExists(var2)) {
- var2 = null;
- }
-
- Enumeration var3 = super.findResources(var1);
- return new 3(this, var3, var2);
- }
- }
- }
-